Start using precise -L flags
authorAlex Crichton <alex@alexcrichton.com>
Sun, 4 Jan 2015 09:16:33 +0000 (01:16 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 6 Jan 2015 01:06:25 +0000 (17:06 -0800)
Now that the compiler supports the notion for a "dependency lookup path" Cargo
can specify this information to the compiler in order to prevent transitive
dependencies from being imported.

Closes #1037

Cargo.lock
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_build_lib.rs
tests/test_cargo_compile.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_profiles.rs

index 0f08ca28499267c83de89e711de0fd90ada02418..c761cc25fbaeebaa64ee5e3478d118e82ad64b2f 100644 (file)
@@ -3,7 +3,7 @@ name = "cargo"
 version = "0.1.0"
 dependencies = [
  "curl 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "docopt 0.6.22 (registry+https://github.com/rust-lang/crates.io-index)",
+ "docopt 0.6.23 (registry+https://github.com/rust-lang/crates.io-index)",
  "flate2 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "git2 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "glob 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -40,7 +40,7 @@ dependencies = [
 
 [[package]]
 name = "docopt"
-version = "0.6.22"
+version = "0.6.23"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "regex 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
index a9902f88041497bd98b4280defd5ba660d8319cc..c3d43e2e54155b69fb9f925549a8da4ab8c109a2 100644 (file)
@@ -727,8 +727,8 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
                    cx: &Context,
                    kind: Kind) -> CargoResult<CommandPrototype> {
     let layout = cx.layout(package, kind);
-    cmd = cmd.arg("-L").arg(layout.root());
-    cmd = cmd.arg("-L").arg(layout.deps());
+    cmd = cmd.arg("-L").arg(format!("dependency={}", layout.root().display()));
+    cmd = cmd.arg("-L").arg(format!("dependency={}", layout.deps().display()));
 
     cmd = cmd.env("OUT_DIR", if package.has_custom_build() {
         Some(layout.build_out(package))
@@ -746,7 +746,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
         }
     });
     for dir in dirs.into_iter() {
-        cmd = cmd.arg("-L").arg(dir);
+        cmd = cmd.arg("-L").arg(format!("native={}", dir.display()));
     }
 
     for &(pkg, target) in cx.dep_targets(package, target).iter() {
@@ -757,8 +757,9 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
         target.is_lib() && target.get_profile().is_compile()
     });
 
-    if target.is_bin() && !target.get_profile().is_custom_build() {
-        for target in targets.filter(|f| !f.is_staticlib()) {
+    if (target.is_bin() || target.is_example()) &&
+       !target.get_profile().is_custom_build() {
+        for target in targets.filter(|f| f.is_rlib() || f.is_dylib()) {
             cmd = try!(link_to(cmd, package, target, cx, kind));
         }
     }
@@ -777,6 +778,7 @@ fn build_deps_args(mut cmd: CommandPrototype, target: &Target, package: &Package
         });
 
         for filename in try!(cx.target_filenames(target)).iter() {
+            if filename.as_bytes().ends_with(b".a") { continue }
             let mut v = Vec::new();
             v.push_all(target.get_name().as_bytes());
             v.push(b'=');
index f559b53e8c8c0024ac8152e8f858cc925a9aadce..6da91566935b7b826d55bc49bce9572373dde74f 100644 (file)
@@ -14,8 +14,8 @@ fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target \
         --emit=dep-info,link \
-        -L {dir}{sep}target \
-        -L {dir}{sep}target{sep}deps`
+        -L dependency={dir}{sep}target \
+        -L dependency={dir}{sep}target{sep}deps`
 ",
             running = RUNNING, compiling = COMPILING, sep = path::SEP,
             dir = p.root().display(), url = p.url(),
index 2572cf0ef00e2bcc839abea4a57e96e05114a44c..4c333dcc39a03558a6d138b3e3d1cb95def02188 100644 (file)
@@ -757,8 +757,8 @@ test!(lto_build {
         --cfg ndebug \
         --out-dir {dir}{sep}target{sep}release \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release \
-        -L {dir}{sep}target{sep}release{sep}deps`
+        -L dependency={dir}{sep}target{sep}release \
+        -L dependency={dir}{sep}target{sep}release{sep}deps`
 ",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
@@ -785,8 +785,8 @@ test!(verbose_build {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target \
         --emit=dep-info,link \
-        -L {dir}{sep}target \
-        -L {dir}{sep}target{sep}deps`
+        -L dependency={dir}{sep}target \
+        -L dependency={dir}{sep}target{sep}deps`
 ",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
@@ -815,8 +815,8 @@ test!(verbose_release_build {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target{sep}release \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release \
-        -L {dir}{sep}target{sep}release{sep}deps`
+        -L dependency={dir}{sep}target{sep}release \
+        -L dependency={dir}{sep}target{sep}release{sep}deps`
 ",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
@@ -861,8 +861,8 @@ test!(verbose_release_build_deps {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target{sep}release{sep}deps \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release{sep}deps \
-        -L {dir}{sep}target{sep}release{sep}deps`
+        -L dependency={dir}{sep}target{sep}release{sep}deps \
+        -L dependency={dir}{sep}target{sep}release{sep}deps`
 {compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         -C opt-level=3 \
@@ -871,8 +871,8 @@ test!(verbose_release_build_deps {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target{sep}release \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release \
-        -L {dir}{sep}target{sep}release{sep}deps \
+        -L dependency={dir}{sep}target{sep}release \
+        -L dependency={dir}{sep}target{sep}release{sep}deps \
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
                      {prefix}foo-[..]{suffix} \
         --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
@@ -1119,7 +1119,7 @@ test!(staticlib_rlib_and_bin {
                   foo::foo();
               }"#);
 
-    assert_that(p.cargo_process("build"), execs().with_status(0));
+    assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0));
 });
 
 test!(opt_out_of_lib {
@@ -1523,3 +1523,47 @@ test!(compile_then_delete {
     assert_that(p.process(cargo_dir().join("cargo")).arg("run"),
                 execs().with_status(0));
 });
+
+test!(transitive_dependencies_not_available {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies.a]
+            path = "a"
+        "#)
+        .file("src/main.rs", "extern crate b; extern crate a; fn main() {}")
+        .file("a/Cargo.toml", r#"
+            [package]
+            name = "a"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies.b]
+            path = "../b"
+        "#)
+        .file("a/src/lib.rs", "extern crate b;")
+        .file("b/Cargo.toml", r#"
+            [package]
+            name = "b"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("b/src/lib.rs", "");
+
+    assert_that(p.cargo_process("build").arg("-v"),
+                execs().with_status(101)
+                       .with_stderr("\
+[..] can't find crate for `b`
+[..] extern crate b; [..]
+[..]
+error: aborting due to previous error
+Could not compile `foo`.
+
+Caused by:
+  [..]
+"));
+});
index b55cc75d9c9ed41d68d71877663cacc92a1b2b98..e33eeb5eb1199b360cfc87eccfcc4e15bfa5a27f 100644 (file)
@@ -303,8 +303,8 @@ test!(linker_and_ar {
     --emit=dep-info,link \
     --target {target} \
     -C ar=my-ar-tool -C linker=my-linker-tool \
-    -L {dir}{sep}target{sep}{target} \
-    -L {dir}{sep}target{sep}{target}{sep}deps`
+    -L dependency={dir}{sep}target{sep}{target} \
+    -L dependency={dir}{sep}target{sep}{target}{sep}deps`
 ",
                             running = RUNNING,
                             compiling = COMPILING,
index ccf531a540f9d4b15a72421154944ad9683e30cd..5479fafe98ca50ed9ce80a2b0ed2605d0e0335ce 100644 (file)
@@ -35,8 +35,8 @@ test!(profile_overrides {
         -C rpath \
         --out-dir {dir}{sep}target \
         --emit=dep-info,link \
-        -L {dir}{sep}target \
-        -L {dir}{sep}target{sep}deps`
+        -L dependency={dir}{sep}target \
+        -L dependency={dir}{sep}target{sep}deps`
 ",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
 dir = p.root().display(),
@@ -89,8 +89,8 @@ test!(top_level_overrides_deps {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target{sep}release{sep}deps \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release{sep}deps \
-        -L {dir}{sep}target{sep}release{sep}deps`
+        -L dependency={dir}{sep}target{sep}release{sep}deps \
+        -L dependency={dir}{sep}target{sep}release{sep}deps`
 {compiling} test v0.0.0 ({url})
 {running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
         -C opt-level=1 \
@@ -99,8 +99,8 @@ test!(top_level_overrides_deps {
         -C extra-filename=-[..] \
         --out-dir {dir}{sep}target{sep}release \
         --emit=dep-info,link \
-        -L {dir}{sep}target{sep}release \
-        -L {dir}{sep}target{sep}release{sep}deps \
+        -L dependency={dir}{sep}target{sep}release \
+        -L dependency={dir}{sep}target{sep}release{sep}deps \
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
                      {prefix}foo-[..]{suffix} \
         --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`